* Table A1: Baseline comparison between balanced panel and full sample
* Sample used to study investments and agricultural outcomes
* Last Updated, Niriksha Shetty 03/31/206

clear
clear mata
clear matrix
set maxvar 20000
set more off

pwd
cap cd c(`pwd')

estimates clear

use "../dta/reduced-form-master.dta", clear


estimates clear

* creating baseline demographic vars
gen w1_head_educ=.
gen w1_age_head=.
forvalues a=1/18 {
replace w1_head_educ=a18_c`a' if a13_c`a' == 1 & mkt_year==2005
replace w1_age_head=a14_c`a' if a13_c`a' == 1 & mkt_year==2005
replace w1_head_educ=. if w1_age_head<18 & mkt_year==2005
replace w1_age_head=. if w1_age_head<18 & mkt_year==2005
replace w1_head_educ=0 if w1_head_educ==888 
replace w1_head_educ=0 if w1_head_educ==15 | w1_head_educ==16
}

replace sex=0 if sex==2
rename sex male
lab var male "=1 if male"

cap drop finlit_new
egen finlit_new=rowmean(l21c l22c l23c l32c l32c l33c l34c l35c l36c l41c l42c l43c l44c)


gen w1_hasplot = hasplot if mkt_year==2005
gen w1_finlit = finlit_new if mkt_year==2005
gen w1_wealth_index = wealth_index if mkt_year==2005

* combined treatment var
gen treatment_cat=0
replace treatment_cat=1 if originaltvillage==1
replace treatment_cat=2 if firstt_2007==1

local vars "w1_age_head w1_head_educ w1_hasplot w1_finlit w1_wealth_index kval_w1_real cost_k_w1_real b110rk_w1_real b111rk_w1_real b112pk_w1_real total_mandays_k_w1 total_hired_mandays_k_w1 total_fam_mandays_k_w1 profit_k_w1_real fraction_hy_k fraction_cashcrop_k plotsize_ha totalrevenues_w1_real totalcosts_w1_real totalprofit_w1_real"
qui estpost summarize `vars' if mkt_year==2005
est sto A 
qui estpost summarize `vars' if bal_panel3 & mkt_year==2005 
est sto B 
qui estpost summarize `vars' if mkt_year==2005 & treatment_cat==1
est sto C
qui estpost summarize `vars' if bal_panel3 & mkt_year==2005 & treatment_cat==1
est sto D 
qui estpost summarize `vars' if mkt_year==2005 & treatment_cat==2
est sto E 
qui estpost summarize `vars' if bal_panel3 & mkt_year==2005 & treatment_cat==2
est sto F 
qui estpost summarize `vars' if mkt_year==2005 & treatment_cat==0
est sto G
qui estpost summarize `vars' if bal_panel3 & mkt_year==2005 & treatment_cat==0
est sto H

esttab A B C D E F G H using "../output/sum-a1.csv", cells("mean(fmt(2))" replace sd(par fmt(2))) nolabel noabbrev title("Summary statistics") collabels("Mean") mtitle("Full" "Balanced" "T1 full" "t1 bal" "t2 full" "t2 bal" "control full" "contol bal") nonum replace 

*gen bal_panel_treat_dummy = bal_panel3*treatment_cat
tempvar tmp
gen `tmp' = .
foreach var of local vars {
xi:reg `var' bal_panel3 if mkt_year == 2005, cluster(villageno)
replace `tmp' = Ftail(e(df_m),e(df_r),e(F))
label var `tmp' `var'
estpost summarize `tmp' if mkt_year == 2005
est sto A
replace `tmp' = .
replace `tmp' = .
xi:reg `var' bal_panel3 if originaltvillage & mkt_year == 2005, cluster(villageno)
replace `tmp' = Ftail(e(df_m),e(df_r),e(F))
label var `tmp' `var'
estpost summarize `tmp' if mkt_year == 2005
est sto B
replace `tmp' = .
xi:reg `var' bal_panel3 if firstt_2007 & mkt_year == 2005, cluster(villageno)
replace `tmp' = Ftail(e(df_m),e(df_r),e(F))
label var `tmp' `var'
estpost summarize `tmp' if mkt_year == 2005
est sto C
replace `tmp' = .
xi:reg `var' bal_panel3 if firstt_2007==0 & originaltvillage==0 & mkt_year == 2005, cluster(villageno)
replace `tmp' = Ftail(e(df_m),e(df_r),e(F))
label var `tmp' `var'
estpost summarize `tmp' if mkt_year == 2005
est sto D
replace `tmp' = .
esttab A B C D using "../output/bal-a1.csv", cells("mean(fmt(2))") label noabbrev collabels("p-value") mtitle("") noobs nonum append
estimates clear
}


